package cn.kgc.mybatis.day02.dao.impl;

import cn.kgc.mybatis.day02.dao.UserDao;
import cn.kgc.mybatis.day02.entity.User;
import cn.kgc.mybatis.utils.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @author 课工场
 * @date 2024/10/25
 * @description   mybatis编写实现类
 */
public class UserDaoImpl implements UserDao {

    @Override
    public List<User> selectUserList() {
        // sqlSession
        SqlSession sqlSession = MybatisUtil.createSqlSession();
        List<User> users = sqlSession.selectList("user.list");
        return users;
    }

    @Override
    public User getOne(Integer id) {
        // sqlSession
        SqlSession sqlSession = MybatisUtil.createSqlSession();
        User user = sqlSession.selectOne("user.getOne", id);

        return user;
    }
}
